package com.my.goodsmanage.service;

import com.my.goodsmanage.entity.Thing;
import com.my.goodsmanage.enums.ThingEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * @author 徐佳辉
 * @date 2020/10/8 15:43
 */
@Slf4j
@Component
@EnableScheduling
public class EveDay {

    @Autowired
    private ThingService thingService;


    /**
     * 每天半夜12点让所有事件未完成
     */
    @Scheduled(cron = "0 0 0 * * ?")
    public void EveryDayThingToNoFinish(){
        log.info("定时任务执行开始执行 : [{}]",new Date());
        List<Thing> list = thingService.list();
        for (Thing thing : list) {
            thing.setState(ThingEnum.NOT_FINISH.getCode());

        }
        thingService.updateBatchById(list);
        log.info("定时任务执行结束 : [{}]",new Date());

    }
}
